home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: netcom.com!mikenann
- From: Michael Glassman and Ann Ross <mikenann@netcom.com>
- Subject: Re: extern consts
- Content-Type: text/plain; charset=us-ascii
- Message-ID: <314CE209.59EB@netcom.com>
- Sender: mikenann@netcom16.netcom.com
- Content-Transfer-Encoding: 7bit
- Organization: NETCOM On-line Communication Services (408 261-4700 guest)
- References: <4idbcv$ue2@news7.erols.com> <314c2077.138956468@nntp.ix.netcom.com> <4ii7h9$bq6@news6.erols.com>
- Mime-Version: 1.0
- Date: Mon, 18 Mar 1996 04:09:45 GMT
- X-Mailer: Mozilla 2.0 (Win16; I)
-
- Chris Cobb wrote:
- >
- > miker3@ix.netcom.com (Mike Rubenstein) wrote:
- > >
- > >It's not legal. extern const is legal, but in any compilation unit
- > >that does not see the initializer the const variable is not a constant
- > >expression.
- > >
- >
- > Well, your comment makes sense. However, in a way it seem
- > self-contradictory. If a const can be extern, then it no longer is a
- > const: you've basically externed away constness. But if thats what
- > externinig a const does, it doesn't make sense to allow it at all (which
- > is what happens on most compilers.)
- >
- > Chris
-
- Why do you say that extern'ing a const removes its 'constness'? Extern in this case
- just refers to external linkage and global scope. This is required since const
- defaults to 'static' which is file scope. It is still illegal to attempt to change the
- value.
-
- The method for making a global constant is:
-
- file.CC
- extern const float PI=3.14159;
-
- file.h
- extern const float PI;
-
- Including file.h and linking with file.o will give routines access to the global
- constant PI.
-
- Michael Glassman
-